<?php

namespace app\master\controller;

use think\captcha\Captcha;

class Common extends PublicController
{
    /**
     * 文件上传
     */
    public function upload()
    {
        $file = request()->file('file');
        $path = ROOT_PATH . 'public' . DS . 'uploads';
        // 移动到框架应用根目录/public/uploads/ 目录下
        if ($file) {
            $info = $file->rule("uniqid")->move($path);
            if ($info) {
                $url = request()->domain() . request()->root() . "/" . 'uploads' . "/" . $info->getSaveName();
                $this->ajaxReturn(0, '', '', ['src' => $url, "path" => "./uploads/" . $info->getSaveName(), "name" => $info->getSaveName()]);
            } else {
                // 上传失败获取错误信息
                $this->ajaxReturn(0, $file->getError());
            }
        }
    }

    /**
     * 生成验证码
     * @return \think\Response
     */
    public function captcha()
    {
        $config = [
            'codeSet' => '0123456789',
            'length' => 4,
        ];
        $captcha = new Captcha($config);
        return $captcha->entry();
    }

    public function wherelist()
    {
        $id = intval(input('pid'));
        $list = model('company')->getwherelist(['pid' => $id]);
        return $this->ajaxReturn(200, '查询成功', '', $list);
    }

    //汽车品牌型号
    public function gettypelist()
    {
        $id = intval(input('pid'));
        $list = model('carmanage')->gettypelist(['pid' => $id]);
        return $this->ajaxReturn(200, '查询成功', '', $list);
    }
}